﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Space.Library;
using Space.Library.Input;
using Space.Model;
using Space.Model.Entity;

namespace Space
{
    public partial class MainForm : Form
    {
        private GameRunner _runner;


        public MainForm()
        {
            InitializeComponent();

            var painter = new Painter(MainPanel.CreateGraphics());
            _runner = GameRunner.Instance;
            _runner.Painter = painter;

            Debug.Listeners.Clear();
            Debug.Listeners.Add(new DefaultTraceListener { AssertUiEnabled = false});

            _runner.Init(null);
            GlobalTimer.Interval = 1;
            GlobalTimer.Start();
        }

        private void GlobalTimer_Tick(object sender, EventArgs e)
        {
            _runner.Tick();
            GlobalTimer.Start();
        }

        private BoardGrid _boardGrid;

        private void button1_Click(object sender, EventArgs e)
        {
            if (_runner.Entities.Remove(_boardGrid))
            { 
                return;
            }
            _runner.Entities.Insert(0,_boardGrid ?? (_boardGrid = new BoardGrid(Color.FromArgb(30,30,30))));
        }

        private void MainPanel_MouseUp(object sender, MouseEventArgs e)
        {
            var panel = (Panel) sender;

            InputManager.Instance.Click(e.X,e.Y, e.Button);
        }

    }
}
